package com.example.zhinongbao.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;




public class Goods implements Serializable {
   int id;
   String name;
   double price;
   String unit;
   int browseCount;
   String message;
   List<Photo> photoList;
   byte[] img;

   public Goods(int id, String goodsMessage, String goodsName, double goodsPrice, String goodsUnit, int goodsBrowse) {
      this.id=id;
      this.message=goodsMessage;
      this.name=goodsName;
      this.price=goodsPrice;
      this.unit=goodsUnit;
      this.browseCount=goodsBrowse;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public double getPrice() {
      return price;
   }

   public void setPrice(double price) {
      this.price = price;
   }

   public byte[] getImg() {
      return img;
   }

   public String getUnit() {
      return unit;
   }

   public void setUnit(String unit) {
      this.unit = unit;
   }

   public int getBrowseCount() {
      return browseCount;
   }

   public void setBrowseCount(int browseCount) {
      this.browseCount = browseCount;
   }

   public String getMessage() {
      return message;
   }

   public void setMessage(String message) {
      this.message = message;
   }

   public void setImg(byte[] img) {
      this.img = img;
   }

   // Constructor
   public Goods() {
      this.photoList = new ArrayList<>();
   }

   // Getters and Setters
   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   // ... (Other getters and setters)

   public List<Photo> getPhotoList() {
      return Optional.ofNullable(photoList).orElse(new ArrayList<>());
   }

   public void setPhotoList(List<Photo> photoList) {
      this.photoList = photoList;
   }

   // Adding a photo to the photo list
   public void addPhoto(Photo photo) {
      this.photoList.add(photo);
   }

   // Overriding toString method
   @Override
   public String toString() {
      return "Goods{" +
              "id=" + id +
              ", name='" + name + '\'' +
              ", price=" + price +
              ", unit='" + unit + '\'' +
              ", browseCount=" + browseCount +
              ", message='" + message + '\'' +
              ", photoList=" + photoList +
              ", img=" + img +
              '}';
   }

   // Overriding equals and hashCode methods if necessary
   // ...
}